<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <table>
        <tr>
            <td>商品名称:</td>
            <td><input type="text" placeholder="请输入商品名称" name="productName"></td>
        </tr>
        <tr>
            <td>价格:</td>
            <td><input type="text" placeholder="请输入价格" name="price"></td>
        </tr>
        <tr>
            <td>库存:</td>
            <td><input type="text" placeholder="请输入库存" name='stockNum'></td>
        </tr>
        <tr>
            <td>供应商:</td>
            <td><input type="text" placeholder="请输入供应商" name="supplier"></td>
        </tr>
        <tr>
            <td>备注:</td>
            <td><input type="text" placeholder="请输入备注" name="remark"></td>
        </tr>
        <tr>
            <td>
                <input type="button" value="保存" onclick="save()">
                <input type="button" value="返回" onclick="cancel()">
            </td>
        </tr>
    </table>

    <script src="./js/jquery-3.6.0.min.js"></script>
    <script src="./js/api.js"></script>
    <script>
        $(function () {
            let url = window.location.search
            // console.log(url);
            if (url !== '') {
                let id = url.split('?')[1].split('=')[1]
                // console.log(id);
                getById(id).then(res => {
                    let obj = res.data
                    $('[name=productName]').val(obj.productName)
                    $('[name=price]').val(obj.price)
                    $('[name=stockNum]').val(obj.stockNum)
                    $('[name=supplier]').val(obj.supplier)
                    $('[name=remark]').val(obj.remark)

                    console.log(res);
                })
            }
        })
    </script>
</body>

</html>